const express = require('express')
const router = require('./router')
const app = express()
const bodyParser = require('body-parser')
const cors = require('cors')
// app.get('/', (req, res) => {
//   throw new Error('error.....')
//   // res.send('hello express')
// })
// parse application/x-www-form-urlencoded  
app.use(cors())

app.use(bodyParser.urlencoded({ extended: false }))    
// parse application/json  
app.use(bodyParser.json()) 

app.use('/', router)

// function errorHandler(err, req, res, next) {
//   console.log(res)
//   res.status(500).json({
//     error: -1,
//     msg: err.toString()
//   })
// }
// app.use(errorHandler)


// 服务监听
const server = app.listen(5000, () => {
  const {address, port} = server.address()
  console.log(address, port)
})